package com.asp.alumnisystem.adapter;

import android.content.Context;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.asp.alumnisystem.R;

import java.util.List;


/**
 * 首页viewpager显示Fragment的adapter
 */
public class FragmentPagerAdapter extends android.support.v4.app.FragmentPagerAdapter {

    private List<Fragment> fragmentList;
    private Context context;
    private String[] stringArray;

    public FragmentPagerAdapter(Context context, FragmentManager manager,
                                List<Fragment> fragmentList, String[] stringArray){
        super(manager);
        this.context = context;
        this.fragmentList = fragmentList;
        this.stringArray = stringArray;
    }

    @Override
    public Fragment getItem(int position) {
        return fragmentList.get(position);
    }

    @Override
    public int getCount() {
        return fragmentList.size();
    }

    @Nullable
    @Override
    public CharSequence getPageTitle(int position) {
        return stringArray[position];
    }

    public View getTabItemView(int position){
        View view = LayoutInflater.from(context).inflate(R.layout.home_tab_item_layout, null);
        ImageView imageView = view.findViewById(R.id.image_view);
        if (position == 0){
            imageView.setImageResource(R.drawable.home_tab_work_drawable);
        }else if (position == 1){
            imageView.setImageResource(R.drawable.home_tab_msg_drawable);
        }else if (position == getCount() - 1){
            imageView.setImageResource(R.drawable.home_tab_my_drawable);
        }else{
            imageView.setImageResource(R.drawable.home_tab_work_drawable);
        }
        TextView textView = view.findViewById(R.id.textView);
        textView.setText(getPageTitle(position));
        return view;
    }
}
